package me.zhengjie.modules.deviceposition.repository;

import me.zhengjie.modules.deviceposition.domain.DevicePosition;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * @author 张鹏
 * @date 2019-06-05
 */
public interface DevicePositionRepository extends JpaRepository<DevicePosition, Long>, JpaSpecificationExecutor {
    @Query(value = "select device.*,dp.id position_id,dd.label from (\n" +
            "select id device_id,device_name,'dingwei' device_type from people_device\n" +
            "union all\n" +
            "select id,device_name,'huanjingjiance' device_type from  environmental_device\n" +
            "union ALL\n" +
            "select id,device_name,'qitijiance' device_type from gas_device\n" +
            ") device  left join device_position dp on device.device_id = dp.device_id and device.device_type=dp.device_type\n" +
            "left join dict_detail dd on dd.value=device.device_type and dd.dict_id = 8\n" +
            "where device.device_id is not null order by dp.id,dd.sort,device.device_id", nativeQuery = true)
    List<Map<String, String>> deviceDict();
}